package com.example.experiment2.controller;

import com.example.experiment2.entity.Course;
import com.example.experiment2.service.CourseService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {
    private final CourseService courseService;

    public CourseController(CourseService courseService) {
        this.courseService = courseService;
    }

    @GetMapping("/listAll")
    public List<Course> listAll() {
        return courseService.listAll();
    }

    @GetMapping("/getById/{courseId}")
    public Course getById(@PathVariable int courseId) {
        return courseService.getById(courseId);
    }

    @PostMapping("/add")
    public void add(@RequestBody Course course) {
        courseService.add(course);
    }
}

